class ListNode:
    def __init__(self, val=0,  ne = None):
        self.val = val
        self.next = ne


def mergeTwoLists(l1: ListNode, l2: ListNode) -> ListNode:
    if not l1:
        return l2
    if not l2:
        return l1
    h = ListNode(-1)
    hh = h

    while l1 and l2:
        if l1.val < l2.val:
            hh.next = l1
            l1 = l1.next
        else:
            hh.next = l2
            l2 = l2.next
        hh = hh.next
    if l1:
        hh.next = l1
    else:
        hh.next = l2
    return h.next


a = ListNode(1)
a.next = ListNode(4)

b = ListNode(3)
b.next = ListNode(5)

c = mergeTwoLists(a, b)
while c:
    print(c.val)
    c = c.next
